<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Dialogs | Auto.js 4.1.0 文档</title>
  <link rel="stylesheet" href="assets/fonts.css">
  <link rel="stylesheet" href="assets/style.css">
  <link rel="stylesheet" href="assets/sh.css">
  <link rel="canonical" href="https://nodejs.org/api/dialogs.html">
</head>
<body class="alt apidoc" id="api-section-dialogs">
  <div id="content" class="clearfix">
    <div id="column2" class="interior">
      <div id="intro" class="interior">
        <a href="/" title="返回首页">
          Auto.js
        </a>
      </div>
      <ul>
<li><a class="nav-documentation" href="documentation.html">关于本文档</a></li>
<li><a class="nav-http-www-w3school-com-cn-js-pro_js_syntax-asp" href="http://www.w3school.com.cn/js/pro_js_syntax.asp">W3CSchool - ECMAScript教程</a></li>
<li><a class="nav-http-es6-ruanyifeng-com-README" href="http://es6.ruanyifeng.com/#README">阮一峰 - ECMAScript 6教程</a></li>
</ul>
<div class="line"></div>

<ul>
<li><a class="nav-overview" href="overview.html">Overview - 综述</a></li>
<li><a class="nav-qa" href="qa.html">Q&amp;A - 常见问题</a></li>
<li><a class="nav-app" href="app.html">App - 应用</a></li>
<li><a class="nav-console" href="console.html">Console - 控制台</a></li>
<li><a class="nav-coordinates-based-automation" href="coordinates-based-automation.html">CoordinatesBasedAutomation - 基于坐标的操作</a></li>
<li><a class="nav-device" href="device.html">Device - 设备</a></li>
<li><a class="nav-dialogs active" href="dialogs.html">Dialogs - 对话框</a></li>
<li><a class="nav-engines" href="engines.html">Engines - 脚本引擎</a></li>
<li><a class="nav-events" href="events.html">Events - 事件与监听</a></li>
<li><a class="nav-floaty" href="floaty.html">Floaty - 悬浮窗</a></li>
<li><a class="nav-files" href="files.html">Files - 文件系统</a></li>
<li><a class="nav-globals" href="globals.html">Globals - 一般全局函数</a></li>
<li><a class="nav-http" href="http.html">Http - HTTP</a></li>
<li><a class="nav-images" href="images.html">Images - 图片与图色处理</a></li>
<li><a class="nav-keys" href="keys.html">Keys - 按键模拟</a></li>
<li><a class="nav-media" href="media.html">Media - 多媒体</a></li>
<li><a class="nav-modules" href="modules.html">Modules - 模块</a></li>
<li><a class="nav-widgets-based-automation" href="widgets-based-automation.html">WidgetsBasedAutomation - 基于控件的操作</a></li>
<li><a class="nav-sensors" href="sensors.html">Sensors - 传感器</a></li>
<li><a class="nav-shell" href="shell.html">Shell - Shell命令</a></li>
<li><a class="nav-storages" href="storages.html">Storages - 本地存储</a></li>
<li><a class="nav-threads" href="threads.html">Threads - 多线程</a></li>
<li><a class="nav-timers" href="timers.html">Timers - 定时器</a></li>
<li><a class="nav-ui" href="ui.html">UI - 用户界面</a></li>
<li><a class="nav-https-developer-mozilla-org-zh-CN-docs-Mozilla-Projects-Rhino-Scripting_Java" href="https://developer.mozilla.org/zh-CN/docs/Mozilla/Projects/Rhino/Scripting_Java">Work with Java - 调用Java API</a></li>
</ul>
<div class="line"></div>

<ul>
<li><a class="nav-https-github-com-hyb1996-NoRootScriptDroid" href="https://github.com/hyb1996/NoRootScriptDroid">GitHub项目 &amp; Issue提交</a></li>
<li><a class="nav-http-autojs-org" href="http://autojs.org">Auto.js交流社区</a></li>
</ul>

    </div>

    <div id="column1" data-id="dialogs" class="interior">
      <header>
        <h1>Auto.js 4.1.0 文档</h1>
        <div id="gtoc">
          <p>
            <a href="index.html" name="toc">索引</a> |
            <a href="all.html">查看全部</a>
          </p>
        </div>
        <hr>
      </header>

      <div id="toc">
        <h2>目录</h2>
        <ul>
<li><span class="stability_2"><a href="#dialogs_dialogs">Dialogs</a></span><ul>
<li><span class="stability_undefined"><a href="#dialogs_dialogs_alert_title_content_callback">dialogs.alert(title[, content, callback])</a></span></li>
<li><span class="stability_undefined"><a href="#dialogs_dialogs_confirm_title_content_callback">dialogs.confirm(title[, content, callback])</a></span></li>
<li><span class="stability_undefined"><a href="#dialogs_dialogs_rawinput_title_prefill_callback">dialogs.rawInput(title[, prefill, callback])</a></span></li>
<li><span class="stability_undefined"><a href="#dialogs_dialogs_input_title_prefill_callback">dialogs.input(title[, prefill, callback])</a></span></li>
<li><span class="stability_undefined"><a href="#dialogs_dialogs_prompt_title_prefill_callback">dialogs.prompt(title[, prefill, callback])</a></span></li>
<li><span class="stability_undefined"><a href="#dialogs_dialogs_select_title_items_callback">dialogs.select(title, items, callback)</a></span></li>
<li><span class="stability_undefined"><a href="#dialogs_dialogs_singlechoice_title_items_index_callback">dialogs.singleChoice(title, items[, index, callback])</a></span></li>
<li><span class="stability_undefined"><a href="#dialogs_dialogs_multichoice_title_items_indices_callback">dialogs.multiChoice(title, items[, indices, callback])</a></span></li>
<li><span class="stability_undefined"><a href="#dialogs_dialogs_build_properties">dialogs.build(properties)</a></span></li>
</ul>
</li>
<li><span class="stability_undefined"><a href="#dialogs_dialog">Dialog</a></span><ul>
<li><span class="stability_undefined"><a href="#dialogs_show">事件: <code>show</code></a></span></li>
<li><span class="stability_undefined"><a href="#dialogs_cancel">事件: <code>cancel</code></a></span></li>
<li><span class="stability_undefined"><a href="#dialogs_dismiss">事件: <code>dismiss</code></a></span></li>
<li><span class="stability_undefined"><a href="#dialogs_positive">事件: <code>positive</code></a></span></li>
<li><span class="stability_undefined"><a href="#dialogs_negative">事件: <code>negative</code></a></span></li>
<li><span class="stability_undefined"><a href="#dialogs_neutral">事件: <code>neutral</code></a></span></li>
<li><span class="stability_undefined"><a href="#dialogs_any">事件: <code>any</code></a></span></li>
<li><span class="stability_undefined"><a href="#dialogs_item_select">事件: <code>item_select</code></a></span></li>
<li><span class="stability_undefined"><a href="#dialogs_single_choice">事件: <code>single_choice</code></a></span></li>
<li><span class="stability_undefined"><a href="#dialogs_multi_choice">事件: <code>multi_choice</code></a></span></li>
<li><span class="stability_undefined"><a href="#dialogs_input">事件: <code>input</code></a></span></li>
<li><span class="stability_undefined"><a href="#dialogs_input_change">事件: <code>input_change</code></a></span></li>
<li><span class="stability_undefined"><a href="#dialogs_dialog_getprogress">dialog.getProgress()</a></span></li>
<li><span class="stability_undefined"><a href="#dialogs_dialog_getmaxprogress">dialog.getMaxProgress()</a></span></li>
<li><span class="stability_undefined"><a href="#dialogs_dialog_getactionbutton_action">dialog.getActionButton(action)</a></span></li>
</ul>
</li>
</ul>

      </div>

      <div id="apicontent">
        <h1>Dialogs<span><a class="mark" href="#dialogs_dialogs" id="dialogs_dialogs">#</a></span></h1>
<div class="api_stability api_stability_2"><a href="documentation.html#documentation_stability_index">Stability: 2</a> - Stable</div><p>dialogs 模块提供了简单的对话框支持，可以通过对话框和用户进行交互。最简单的例子如下：</p>
<pre><code>alert(&quot;您好&quot;);
</code></pre><p>这段代码会弹出一个消息提示框显示&quot;您好&quot;，并在用户点击&quot;确定&quot;后继续运行。稍微复杂一点的例子如下：</p>
<pre><code>var clear = confirm(&quot;要清除所有缓存吗?&quot;);
if(clear){
    alert(&quot;清除成功!&quot;);
}
</code></pre><p><code>confirm()</code>会弹出一个对话框并让用户选择&quot;是&quot;或&quot;否&quot;，如果选择&quot;是&quot;则返回true。</p>
<p>需要特别注意的是，对话框在ui模式下不能像通常那样使用，应该使用回调函数或者<a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>的形式。理解这一点可能稍有困难。举个例子:</p>
<pre><code>&quot;ui&quot;;
//回调形式
 confirm(&quot;要清除所有缓存吗?&quot;, function(clear){
     if(clear){
          alert(&quot;清除成功!&quot;);
     }
 });
//Promise形式
confirm(&quot;要清除所有缓存吗?&quot;)
    .then(clear =&gt; {
        if(clear){
          alert(&quot;清除成功!&quot;);
        }
    });
</code></pre><h2>dialogs.alert(title[, content, callback])<span><a class="mark" href="#dialogs_dialogs_alert_title_content_callback" id="dialogs_dialogs_alert_title_content_callback">#</a></span></h2>
<div class="signature"><ul>
<li><code>title</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 对话框的标题。</li>
<li><code>content</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 可选，对话框的内容。默认为空。</li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> 回调函数，可选。当用户点击确定时被调用,一般用于ui模式。</li>
</ul>
</div><p>显示一个只包含“确定”按钮的提示对话框。直至用户点击确定脚本才继续运行。</p>
<p>该函数也可以作为全局函数使用。</p>
<pre><code>alert(&quot;出现错误~&quot;, &quot;出现未知错误，请联系脚本作者”);
</code></pre><p>在ui模式下该函数返回一个<code>Promise</code>。例如:</p>
<pre><code>&quot;ui&quot;;
alert(&quot;嘿嘿嘿&quot;).then(()=&gt;{
    //当点击确定后会执行这里
});
</code></pre><h2>dialogs.confirm(title[, content, callback])<span><a class="mark" href="#dialogs_dialogs_confirm_title_content_callback" id="dialogs_dialogs_confirm_title_content_callback">#</a></span></h2>
<div class="signature"><ul>
<li><code>title</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 对话框的标题。</li>
<li><code>content</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 可选，对话框的内容。默认为空。</li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> 回调函数，可选。当用户点击确定时被调用,一般用于ui模式。</li>
</ul>
</div><p>显示一个包含“确定”和“取消”按钮的提示对话框。如果用户点击“确定”则返回 <code>true</code> ，否则返回 <code>false</code> 。</p>
<p>该函数也可以作为全局函数使用。</p>
<p>在ui模式下该函数返回一个<code>Promise</code>。例如:</p>
<pre><code>&quot;ui&quot;;
confirm(&quot;确定吗&quot;).then(value=&gt;{
    //当点击确定后会执行这里, value为true或false, 表示点击&quot;确定&quot;或&quot;取消&quot;
});
</code></pre><h2>dialogs.rawInput(title[, prefill, callback])<span><a class="mark" href="#dialogs_dialogs_rawinput_title_prefill_callback" id="dialogs_dialogs_rawinput_title_prefill_callback">#</a></span></h2>
<div class="signature"><ul>
<li><code>title</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 对话框的标题。</li>
<li><code>prefill</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 输入框的初始内容，可选，默认为空。</li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> 回调函数，可选。当用户点击确定时被调用,一般用于ui模式。</li>
</ul>
</div><p>显示一个包含输入框的对话框，等待用户输入内容，并在用户点击确定时将输入的字符串返回。如果用户取消了输入，返回null。</p>
<p>该函数也可以作为全局函数使用。</p>
<pre><code>var name = rawInput(&quot;请输入您的名字&quot;, &quot;小明&quot;);
alert(&quot;您的名字是&quot; + name);
</code></pre><p>在ui模式下该函数返回一个<code>Promise</code>。例如:</p>
<pre><code>&quot;ui&quot;;
rawInput(&quot;请输入您的名字&quot;, &quot;小明&quot;).then(name =&gt; {
    alert(&quot;您的名字是&quot; + name);
});
</code></pre><p>当然也可以使用回调函数，例如:</p>
<pre><code>rawInput(&quot;请输入您的名字&quot;, &quot;小明&quot;, name =&gt; {
     alert(&quot;您的名字是&quot; + name);
});
</code></pre><h2>dialogs.input(title[, prefill, callback])<span><a class="mark" href="#dialogs_dialogs_input_title_prefill_callback" id="dialogs_dialogs_input_title_prefill_callback">#</a></span></h2>
<p>等效于 <code>eval(dialogs.rawInput(title, prefill, callback))</code>, 该函数和rawInput的区别在于，会把输入的字符串用eval计算一遍再返回，返回的可能不是字符串。</p>
<p>可以用该函数输入数字、数组等。例如：</p>
<pre><code>var age = dialogs.input(&quot;请输入您的年龄&quot;, &quot;18&quot;);
// new Date().getYear() + 1900 可获取当前年份
var year = new Date().getYear() + 1900 - age;
alert(&quot;您的出生年份是&quot; + year);
</code></pre><p>在ui模式下该函数返回一个<code>Promise</code>。例如:</p>
<pre><code>&quot;ui&quot;;
dialogs.input(&quot;请输入您的年龄&quot;, &quot;18&quot;).then(age =&gt; {
    var year = new Date().getYear() + 1900 - age;
    alert(&quot;您的出生年份是&quot; + year);
});
</code></pre><h2>dialogs.prompt(title[, prefill, callback])<span><a class="mark" href="#dialogs_dialogs_prompt_title_prefill_callback" id="dialogs_dialogs_prompt_title_prefill_callback">#</a></span></h2>
<p>相当于 <code>dialogs.rawInput()</code>;</p>
<h2>dialogs.select(title, items, callback)<span><a class="mark" href="#dialogs_dialogs_select_title_items_callback" id="dialogs_dialogs_select_title_items_callback">#</a></span></h2>
<div class="signature"><ul>
<li><code>title</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 对话框的标题。</li>
<li><code>items</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" class="type">&lt;Array&gt;</a> 对话框的选项列表，是一个字符串数组。</li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> 回调函数，可选。当用户点击确定时被调用,一般用于ui模式。</li>
</ul>
</div><p>显示一个带有选项列表的对话框，等待用户选择，返回用户选择的选项索引(0 ~ item.length - 1)。如果用户取消了选择，返回-1。</p>
<pre><code>var options = [&quot;选项A&quot;, &quot;选项B&quot;, &quot;选项C&quot;, &quot;选项D&quot;]
var i = dialogs.select(&quot;请选择一个选项&quot;, options);
if(i &gt;= 0){
    toast(&quot;您选择的是&quot; + options[i]);
}else{
    toast(&quot;您取消了选择&quot;);
}
</code></pre><p>在ui模式下该函数返回一个<code>Promise</code>。例如:</p>
<pre><code>&quot;ui&quot;;
dialogs.select(&quot;请选择一个选项&quot;, [&quot;选项A&quot;, &quot;选项B&quot;, &quot;选项C&quot;, &quot;选项D&quot;])
    .then(i =&gt; {
        toast(i);
    });
</code></pre><h2>dialogs.singleChoice(title, items[, index, callback])<span><a class="mark" href="#dialogs_dialogs_singlechoice_title_items_index_callback" id="dialogs_dialogs_singlechoice_title_items_index_callback">#</a></span></h2>
<div class="signature"><ul>
<li><code>title</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 对话框的标题。</li>
<li><code>items</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" class="type">&lt;Array&gt;</a> 对话框的选项列表，是一个字符串数组。</li>
<li><code>index</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> 对话框的初始选项的位置，默认为0。</li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> 回调函数，可选。当用户点击确定时被调用,一般用于ui模式。</li>
</ul>
</div><p>显示一个单选列表对话框，等待用户选择，返回用户选择的选项索引(0 ~ item.length - 1)。如果用户取消了选择，返回-1。</p>
<p>在ui模式下该函数返回一个<code>Promise</code>。</p>
<h2>dialogs.multiChoice(title, items[, indices, callback])<span><a class="mark" href="#dialogs_dialogs_multichoice_title_items_indices_callback" id="dialogs_dialogs_multichoice_title_items_indices_callback">#</a></span></h2>
<div class="signature"><ul>
<li><code>title</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 对话框的标题。</li>
<li><code>items</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" class="type">&lt;Array&gt;</a> 对话框的选项列表，是一个字符串数组。</li>
<li><code>indices</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" class="type">&lt;Array&gt;</a> 选项列表中初始选中的项目索引的数组，默认为空数组。</li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> 回调函数，可选。当用户点击确定时被调用,一般用于ui模式。</li>
</ul>
</div><p>显示一个多选列表对话框，等待用户选择，返回用户选择的选项索引的数组。如果用户取消了选择，返回<code>[]</code>。</p>
<p>在ui模式下该函数返回一个<code>Promise</code>。</p>
<h2>dialogs.build(properties)<span><a class="mark" href="#dialogs_dialogs_build_properties" id="dialogs_dialogs_build_properties">#</a></span></h2>
<div class="signature"><ul>
<li><code>properties</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> 对话框属性，用于配置对话框。</li>
<li>返回 <span class="type">&lt;Dialog&gt;</span></li>
</ul>
</div><p>创建一个可自定义的对话框，例如：</p>
<pre><code>dialogs.build({
    //对话框标题
    title: &quot;发现新版本&quot;,
    //对话框内容
    content: &quot;更新日志: 新增了若干了BUG&quot;,
    //确定键内容
    positive: &quot;下载&quot;,
    //取消键内容
    negative: &quot;取消&quot;,
    //中性键内容
    neutral: &quot;到浏览器下载&quot;,
    //勾选框内容
    checkBoxPrompt: &quot;不再提示&quot;
}).on(&quot;positive&quot;, ()=&gt;{
    //监听确定键
    toast(&quot;开始下载....&quot;);
}).on(&quot;neutral&quot;, ()=&gt;{
    //监听中性键
    app.openUrl(&quot;https://www.autojs.org&quot;);
}).on(&quot;check&quot;, (checked)=&gt;{
    //监听勾选框
    log(checked);
}).show();
</code></pre><p>选项properties可供配置的项目为:</p>
<ul>
<li><code>title</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 对话框标题</li>
<li><code>titleColor</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> 对话框标题的颜色</li>
<li><code>buttonRippleColor</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> 对话框按钮的波纹效果颜色</li>
<li><code>icon</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> | <span class="type">&lt;Image&gt;</span> 对话框的图标，是一个URL或者图片对象 </li>
<li><code>content</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 对话框文字内容 </li>
<li><code>contentColor</code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> 对话框文字内容的颜色</li>
<li><code>contentLineSpacing</code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> 对话框文字内容的行高倍数，1.0为一倍行高</li>
<li><code>items</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" class="type">&lt;Array&gt;</a> 对话框列表的选项</li>
<li><code>itemsColor</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> 对话框列表的选项的文字颜色</li>
<li><code>itemsSelectMode</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 对话框列表的选项选择模式，可以为:<ul>
<li><code>select</code> 普通选择模式</li>
<li><code>single</code> 单选模式</li>
<li><code>multi</code> 多选模式</li>
</ul>
</li>
<li><code>itemsSelectedIndex</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" class="type">&lt;Array&gt;</a> 对话框列表中预先选中的项目索引，如果是单选模式为一个索引；多选模式则为数组</li>
<li><code>positive</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 对话框确定按钮的文字内容(最右边按钮)</li>
<li><code>positiveColor</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> 对话框确定按钮的文字颜色(最右边按钮)</li>
<li><code>neutral</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 对话框中立按钮的文字内容(最左边按钮)</li>
<li><code>neutralColor</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> 对话框中立按钮的文字颜色(最左边按钮)</li>
<li><code>negative</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 对话框取消按钮的文字内容(确定按钮左边的按钮)</li>
<li><code>negativeColor</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> 对话框取消按钮的文字颜色(确定按钮左边的按钮)</li>
<li><code>checkBoxPrompt</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 勾选框文字内容</li>
<li><code>checkBoxChecked</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> 勾选框是否勾选 </li>
<li><code>progress</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> 配置对话框进度条的对象：<ul>
<li><code>max</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> 进度条的最大值，如果为-1则为无限循环的进度条</li>
<li><code>horizontal</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> 如果为true, 则对话框无限循环的进度条为水平进度条</li>
<li><code>showMinMax</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> 是否显示进度条的最大值和最小值</li>
</ul>
</li>
<li><code>cancelable</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> 对话框是否可取消，如果为false，则对话框只能用代码手动取消</li>
<li><code>canceledOnTouchOutside</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> 对话框是否在点击对话框以外区域时自动取消，默认为true</li>
<li><code>inputHint</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 对话框的输入框的输入提示</li>
<li><code>inputPrefill</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 对话框输入框的默认输入内容</li>
</ul>
<p>通过这些选项可以自定义一个对话框，并通过监听返回的Dialog对象的按键、输入事件来实现交互。下面是一些例子。</p>
<p>模拟alert对话框：</p>
<pre><code>dialogs.build({
    title: &quot;你好&quot;,
    content: &quot;今天也要元气满满哦&quot;,
    positive: &quot;好的&quot;
}).show();
</code></pre><p>模拟confirm对话框:</p>
<pre><code>dialogs.build({
    title: &quot;你好&quot;,
    content: &quot;请问你是笨蛋吗?&quot;,
    positive: &quot;是的&quot;,
    negative: &quot;我是大笨蛋&quot;
}).on(&quot;positive&quot;, ()=&gt;{
    alert(&quot;哈哈哈笨蛋&quot;);
}).on(&quot;negative&quot;, ()=&gt;{
    alert(&quot;哈哈哈大笨蛋&quot;);
}).show();
</code></pre><p>模拟单选框:</p>
<pre><code>dialogs.build({
    title: &quot;单选&quot;,
    items: [&quot;选项1&quot;, &quot;选项2&quot;, &quot;选项3&quot;, &quot;选项4&quot;],
    itemsSelectMode: &quot;single&quot;,
    itemsSelectedIndex: 3
}).on(&quot;single_choice&quot;, (index, item)=&gt;{
    toast(&quot;您选择的是&quot; + item);
}).show();
</code></pre><p>&quot;处理中&quot;对话框:</p>
<pre><code>var d = dialogs.build({
    title: &quot;下载中...&quot;,
    progress: {
        max: -1
    },
    cancelable: false
}).show();

setTimeout(()=&gt;{
    d.dismiss();
}, 3000);
</code></pre><p>输入对话框:</p>
<pre><code>dialogs.build({
    title: &quot;请输入您的年龄&quot;,
    inputPrefill: &quot;18&quot;
}).on(&quot;input&quot;, (input)=&gt;{
    var age = parseInt(input);
    toastLog(age);
}).show();
</code></pre><p>使用这个函数来构造对话框，一个明显的不同是需要使用回调函数而不能像dialogs其他函数一样同步地返回结果；但也可以通过threads模块的方法来实现。例如显示一个输入框并获取输入结果为：</p>
<pre><code>var input = threads.disposable();
dialogas.build({
    title: &quot;请输入您的年龄&quot;,
    inputPrefill: &quot;18&quot;
}).on(&quot;input&quot;, text =&gt; {
    input.setAndNotify(text);
}).show();
var age = parseInt(input.blockedGet());
tosatLog(age);
</code></pre><h1>Dialog<span><a class="mark" href="#dialogs_dialog" id="dialogs_dialog">#</a></span></h1>
<p><code>dialogs.build()</code>返回的对话框对象，内置一些事件用于响应用户的交互，也可以获取对话框的状态和信息。</p>
<h2>事件: <code>show</code><span><a class="mark" href="#dialogs_show" id="dialogs_show">#</a></span></h2>
<div class="signature"><ul>
<li><code>dialog</code> <span class="type">&lt;Dialog&gt;</span> 对话框</li>
</ul>
</div><p>对话框显示时会触发的事件。例如：</p>
<pre><code>dialogs.build({
    title: &quot;标题&quot;
}).on(&quot;show&quot;, (dialog)=&gt;{
    toast(&quot;对话框显示了&quot;);
}).show();
</code></pre><h2>事件: <code>cancel</code><span><a class="mark" href="#dialogs_cancel" id="dialogs_cancel">#</a></span></h2>
<div class="signature"><ul>
<li><code>dialog</code> <span class="type">&lt;Dialog&gt;</span> 对话框</li>
</ul>
</div><p>对话框被取消时会触发的事件。一个对话框可能按取消按钮、返回键取消或者点击对话框以外区域取消。例如：</p>
<pre><code>dialogs.build({
    title: &quot;标题&quot;,
    positive: &quot;确定&quot;,
    negative: &quot;取消&quot;
}).on(&quot;cancel&quot;, (dialog)=&gt;{
    toast(&quot;对话框取消了&quot;);
}).show();
</code></pre><h2>事件: <code>dismiss</code><span><a class="mark" href="#dialogs_dismiss" id="dialogs_dismiss">#</a></span></h2>
<div class="signature"><ul>
<li><code>dialog</code> <span class="type">&lt;Dialog&gt;</span> 对话框</li>
</ul>
</div><p>对话框消失时会触发的事件。对话框被取消或者手动调用<code>dialog.dismiss()</code>函数都会触发该事件。例如：</p>
<pre><code>var d = dialogs.build({
    title: &quot;标题&quot;,
    positive: &quot;确定&quot;,
    negative: &quot;取消&quot;
}).on(&quot;dismiss&quot;, (dialog)=&gt;{
    toast(&quot;对话框消失了&quot;);
}).show();

setTimeout(()=&gt;{
    d.dismiss();
}, 5000);
</code></pre><h2>事件: <code>positive</code><span><a class="mark" href="#dialogs_positive" id="dialogs_positive">#</a></span></h2>
<div class="signature"><ul>
<li><code>dialog</code> <span class="type">&lt;Dialog&gt;</span> 对话框</li>
</ul>
</div><p>确定按钮按下时触发的事件。例如：</p>
<pre><code>var d = dialogs.build({
    title: &quot;标题&quot;,
    positive: &quot;确定&quot;,
    negative: &quot;取消&quot;
}).on(&quot;positive&quot;, (dialog)=&gt;{
    toast(&quot;你点击了确定&quot;);
}).show();
</code></pre><h2>事件: <code>negative</code><span><a class="mark" href="#dialogs_negative" id="dialogs_negative">#</a></span></h2>
<div class="signature"><ul>
<li><code>dialog</code> <span class="type">&lt;Dialog&gt;</span> 对话框</li>
</ul>
</div><p>取消按钮按下时触发的事件。例如：</p>
<pre><code>var d = dialogs.build({
    title: &quot;标题&quot;,
    positive: &quot;确定&quot;,
    negative: &quot;取消&quot;
}).on(&quot;negative&quot;, (dialog)=&gt;{
    toast(&quot;你点击了取消&quot;);
}).show();
</code></pre><h2>事件: <code>neutral</code><span><a class="mark" href="#dialogs_neutral" id="dialogs_neutral">#</a></span></h2>
<div class="signature"><ul>
<li><code>dialog</code> <span class="type">&lt;Dialog&gt;</span> 对话框</li>
</ul>
</div><p>中性按钮按下时触发的事件。例如：</p>
<pre><code>var d = dialogs.build({
    title: &quot;标题&quot;,
    positive: &quot;确定&quot;,
    negative: &quot;取消&quot;,
    neutral: &quot;稍后提示&quot;
}).on(&quot;positive&quot;, (dialog)=&gt;{
    toast(&quot;你点击了稍后提示&quot;);
}).show();
</code></pre><h2>事件: <code>any</code><span><a class="mark" href="#dialogs_any" id="dialogs_any">#</a></span></h2>
<div class="signature"><ul>
<li><code>dialog</code> <span class="type">&lt;Dialog&gt;</span> 对话框</li>
<li><code>action</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 被点击的按钮，可能的值为:<ul>
<li><code>positive</code> 确定按钮 </li>
<li><code>negative</code> 取消按钮</li>
<li><code>neutral</code> 中性按钮</li>
</ul>
</li>
</ul>
</div><p>任意按钮按下时触发的事件。例如:</p>
<pre><code>var d = dialogs.build({
    title: &quot;标题&quot;,
    positive: &quot;确定&quot;,
    negative: &quot;取消&quot;,
    neutral: &quot;稍后提示&quot;
}).on(&quot;any&quot;, (action, dialog)=&gt;{
    if(action == &quot;positive&quot;){
        toast(&quot;你点击了确定&quot;);
    }else if(action == &quot;negative&quot;){
        toast(&quot;你点击了取消&quot;);
    }
}).show();
</code></pre><h2>事件: <code>item_select</code><span><a class="mark" href="#dialogs_item_select" id="dialogs_item_select">#</a></span></h2>
<div class="signature"><ul>
<li><code>index</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> 被选中的项目索引，从0开始</li>
<li><code>item</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> 被选中的项目</li>
<li><code>dialog</code> <span class="type">&lt;Dialog&gt;</span> 对话框</li>
</ul>
</div><p>对话框列表(itemsSelectMode为&quot;select&quot;)的项目被点击选中时触发的事件。例如：</p>
<pre><code>var d = dialogs.build({
    title: &quot;请选择&quot;,
    positive: &quot;确定&quot;,
    negative: &quot;取消&quot;,
    items: [&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;D&quot;],
    itemsSelectMode: &quot;select&quot;
}).on(&quot;item_select&quot;, (index, item, dialog)=&gt;{
    toast(&quot;您选择的是第&quot; + (index + 1) + &quot;项, 选项为&quot; + item);
}).show();
</code></pre><h2>事件: <code>single_choice</code><span><a class="mark" href="#dialogs_single_choice" id="dialogs_single_choice">#</a></span></h2>
<div class="signature"><ul>
<li><code>index</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> 被选中的项目索引，从0开始</li>
<li><code>item</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> 被选中的项目</li>
<li><code>dialog</code> <span class="type">&lt;Dialog&gt;</span> 对话框</li>
</ul>
</div><p>对话框单选列表(itemsSelectMode为&quot;singleChoice&quot;)的项目被选中并点击确定时触发的事件。例如：</p>
<pre><code>var d = dialogs.build({
    title: &quot;请选择&quot;,
    positive: &quot;确定&quot;,
    negative: &quot;取消&quot;,
    items: [&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;D&quot;],
    itemsSelectMode: &quot;singleChoice&quot;
}).on(&quot;item_select&quot;, (index, item, dialog)=&gt;{
    toast(&quot;您选择的是第&quot; + (index + 1) + &quot;项, 选项为&quot; + item);
}).show();
</code></pre><h2>事件: <code>multi_choice</code><span><a class="mark" href="#dialogs_multi_choice" id="dialogs_multi_choice">#</a></span></h2>
<div class="signature"><ul>
<li><code>indices</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" class="type">&lt;Array&gt;</a> 被选中的项目的索引的数组</li>
<li><code>items</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" class="type">&lt;Array&gt;</a> 被选中的项目的数组</li>
<li><code>dialog</code> <span class="type">&lt;Dialog&gt;</span> 对话框</li>
</ul>
</div><p>对话框多选列表(itemsSelectMode为&quot;multiChoice&quot;)的项目被选中并点击确定时触发的事件。例如：</p>
<pre><code>var d = dialogs.build({
    title: &quot;请选择&quot;,
    positive: &quot;确定&quot;,
    negative: &quot;取消&quot;,
    items: [&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;D&quot;],
    itemsSelectMode: &quot;multiChoice&quot;
}).on(&quot;item_select&quot;, (indices, items, dialog)=&gt;{
    toast(util.format(&quot;您选择的项目为%o, 选项为%o&quot;, indices, items);
}).show();
</code></pre><h2>事件: <code>input</code><span><a class="mark" href="#dialogs_input" id="dialogs_input">#</a></span></h2>
<div class="signature"><ul>
<li><code>text</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 输入框的内容</li>
<li><code>dialog</code> <span class="type">&lt;Dialog&gt;</span> 对话框</li>
</ul>
</div><p>带有输入框的对话框当点击确定时会触发的事件。例如：</p>
<pre><code>dialogs.build({
    title: &quot;请输入&quot;,
    positive: &quot;确定&quot;,
    negative: &quot;取消&quot;,
    inputPrefill: &quot;&quot;
}).on(&quot;input&quot;, (text, dialog)=&gt;{
    toast(&quot;你输入的是&quot; + text);
}).show();
</code></pre><h2>事件: <code>input_change</code><span><a class="mark" href="#dialogs_input_change" id="dialogs_input_change">#</a></span></h2>
<div class="signature"><ul>
<li><code>text</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 输入框的内容</li>
<li><code>dialog</code> <span class="type">&lt;Dialog&gt;</span> 对话框</li>
</ul>
</div><p>对话框的输入框的文本发生变化时会触发的事件。例如：</p>
<pre><code>dialogs.build({
    title: &quot;请输入&quot;,
    positive: &quot;确定&quot;,
    negative: &quot;取消&quot;,
    inputPrefill: &quot;&quot;
}).on(&quot;input_change&quot;, (text, dialog)=&gt;{
    toast(&quot;你输入的是&quot; + text);
}).show();
</code></pre><h2>dialog.getProgress()<span><a class="mark" href="#dialogs_dialog_getprogress" id="dialogs_dialog_getprogress">#</a></span></h2>
<div class="signature"><ul>
<li>返回 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
</ul>
</div><p>获取当前进度条的进度值，是一个整数</p>
<h2>dialog.getMaxProgress()<span><a class="mark" href="#dialogs_dialog_getmaxprogress" id="dialogs_dialog_getmaxprogress">#</a></span></h2>
<div class="signature"><ul>
<li>返回 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
</ul>
</div><p>获取当前进度条的最大进度值，是一个整数</p>
<h2>dialog.getActionButton(action)<span><a class="mark" href="#dialogs_dialog_getactionbutton_action" id="dialogs_dialog_getactionbutton_action">#</a></span></h2>
<div class="signature"><ul>
<li><code>action</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 动作，包括:<ul>
<li><code>positive</code> </li>
<li><code>negative</code></li>
<li><code>neutral</code></li>
</ul>
</li>
</ul>
</div>
      </div>
    </div>
  </div>
  <script src="assets/sh_main.js"></script>
  <script src="assets/sh_javascript.min.js"></script>
  <script>highlight(undefined, undefined, 'pre');</script>
  <!-- __TRACKING__ -->
</body>
</html>